﻿namespace ConsoleClient
{
    using DemoService;
    using System;
    using System.ServiceModel;

    class Program
    {
        static void Main( string[] args )
        {
            Console.WriteLine( "Please enter a message to reverse..." );
            var message = Console.ReadLine();

            Console.WriteLine( "What source would you like to use:" );
            Console.WriteLine( "[0] Console Hosted Service" );
            Console.WriteLine( "[1] IIS Hosted Service" );

            var choice = Console.ReadLine();

            switch(choice)
            {
                case "0":
                    SendMessageForReversal( message );
                    break;
                case "1":
                    SendMessageToIISForReversal( message );
                    break;
            }

            Console.ReadLine();
        }

        static void SendMessageForReversal(String message)
        {
            var httpBinding = new BasicHttpBinding( BasicHttpSecurityMode.None );
            var endpoint = new EndpointAddress( "http://localhost:8000" );

            var proxy = ChannelFactory<IComposedService>.CreateChannel( httpBinding, endpoint );

            var result = proxy.Reverser( message );

            Console.WriteLine( result );
        }

        static void SendMessageToIISForReversal(String message)
        {
            var binding = new BasicHttpBinding( BasicHttpSecurityMode.None );
            var endpoint = new EndpointAddress( "http://localhost:60480/IISDemo.svc" );

            var proxy = ChannelFactory<IComposedService>.CreateChannel( binding, endpoint );

            var result = proxy.Reverser( message );

            Console.WriteLine( result );
        }
    }
}
;